/*
 * 文件名： BisRealNameCertifyDAOImpl.java
 * 
 * 工程名称: bis-dao
 *
 * Gopay
 *
 * 创建日期： 2016年6月12日
 *
 * Copyright(C) 2016, by www.gopay.com.cn Inc.All rights reserved.
 *
 * 原始作者: 宣广海
 *
 */
package com.gopay.bis.dao.tolly.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.gopay.bis.dao.tolly.BisRealNameCertifyDAO;
import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.cipher.utils.SensitiveInfoUtils;
import com.gopay.common.domain.bis.BisRealNameCertify;

/**
 * 实名认证数据库操作
 *
 * @author 宣广海
 *
 * @version
 *
 * @since 2016年6月12日
 */
@Repository(value = "bisRealNameCertifyDAO")
public class BisRealNameCertifyDAOImpl extends BaseDAOImpl<BisRealNameCertify, String>implements BisRealNameCertifyDAO {
	/**
	 * 定义日志对象
	 */
	private static final Logger logger = LoggerFactory.getLogger(BisRealNameCertifyDAOImpl.class);
	@Override
	public BisRealNameCertify getBisRealNameCertify(String name, String cardNo, String certifyCode) {
		/**
		 * 定义查询SQL
		 */
//		StringBuffer hql = new StringBuffer("FROM BisRealNameCertify where name=:name and cardNo=:cardNo and certifyCode=:certifyCode");
		
		/** 央行检测 修改手机号  modify by ssj 2017-05-05  加密  考虑到后期可能会有多个秘钥体系采用in进行查询*/
    	StringBuffer hql = new StringBuffer("FROM BisRealNameCertify where name in(:name) and cardNo in(:cardNo) and certifyCode=:certifyCode");
        /**end*/
	
		/**
		 * 封装查询条件
		 */
		Map<String, Object> param = new HashMap<String, Object>();
//		param.put("name", name);
//		param.put("cardNo", cardNo);
		
		/** 央行检测 修改手机号  modify by ssj 2017-05-05  加密  考虑到后期可能会有多个秘钥体系采用in进行查询*/
		param.put("name", SensitiveInfoUtils.getAllHisCipherText(name).toArray());
		param.put("cardNo", SensitiveInfoUtils.getAllHisCipherText(cardNo).toArray());
		
		/**end*/
		param.put("certifyCode", certifyCode);
		
		List<BisRealNameCertify> resultList=null;
		try{
			resultList = this.findByHql(hql.toString(), param);
		}catch(Exception e){
			logger.info("查询实名认证记录出现问题："+e.getMessage());
		}
		if (resultList == null || resultList.size() == 0) {
			return null;
		}
		return resultList.get(0);
	}

	@Override
	public void insertBisRealNameCertify(BisRealNameCertify bisRealNameCertify) {
		this.getHibernateTemplate().save(bisRealNameCertify);

	}

    @Override
    public BisRealNameCertify getBisMobileCertify(String name, String identityCode, String mobile, String outStlmcd) {
        /**
         * 定义查询SQL
         */
//        StringBuffer hql = new StringBuffer("FROM BisRealNameCertify where name=:name and cardNo=:cardNo and mobile=:mobile and certifyCode=:certifyCode ");
    	
    	/** 央行检测 修改手机号  modify by ssj 2017-05-05  加密  考虑到后期可能会有多个秘钥体系采用in进行查询*/
    	StringBuffer hql = new StringBuffer("FROM BisRealNameCertify where name in(:name) and cardNo in(:cardNo) and mobile in(:mobile) and certifyCode=:certifyCode ");
    	/**end*/
    	
        /**
         * 封装查询条件
         */
        Map<String, Object> param = new HashMap<String, Object>();
//        param.put("name", name);
//        param.put("cardNo", identityCode);
//        param.put("mobile", mobile);
        

		/** 央行检测 修改手机号  modify by ssj 2017-05-05  加密  考虑到后期可能会有多个秘钥体系采用in进行查询*/
        param.put("name", SensitiveInfoUtils.getAllHisCipherText(name).toArray());
        param.put("cardNo", SensitiveInfoUtils.getAllHisCipherText(identityCode).toArray());
        param.put("mobile", SensitiveInfoUtils.getAllHisCipherText(mobile).toArray());
        /**end*/
        
        param.put("certifyCode", outStlmcd);
        
        List<BisRealNameCertify> resultList=null;
        try{
            resultList = this.findByHql(hql.toString(), param);
        }catch(Exception e){
            logger.info("查询手机认证记录出现问题："+e.getMessage());
        }
        if (resultList == null || resultList.size() == 0) {
            return null;
        }
        return resultList.get(0);
    }

    @Override
    public BisRealNameCertify getBisBankCardNoCertify(String name, String identityCode, String mobile,
            String bankCardNo, String outStlmcd) {
        
        /**
         * 定义查询SQL
         */
//        StringBuffer hql = new StringBuffer("FROM BisRealNameCertify where name=:name and cardNo=:cardNo and mobile=:mobile and bankCardNo=:bankCardNo and certifyCode=:certifyCode ");
        

		/** 央行检测 修改手机号  modify by ssj 2017-05-05  加密  考虑到后期可能会有多个秘钥体系采用in进行查询*/
    	StringBuffer hql = new StringBuffer("FROM BisRealNameCertify where name in(:name) and cardNo in(:cardNo) and mobile in(:mobile) and bankCardNo in(:bankCardNo) and certifyCode=:certifyCode ");
    	/**end*/
    	
    	/**
         * 封装查询条件
         */
        Map<String, Object> param = new HashMap<String, Object>();
//        param.put("name", name);
//        param.put("cardNo", identityCode);
//        param.put("mobile", mobile);
//        param.put("bankCardNo", bankCardNo);
        
        /** 央行检测 修改手机号  modify by ssj 2017-05-05  加密  考虑到后期可能会有多个秘钥体系采用in进行查询*/
        param.put("name", SensitiveInfoUtils.getAllHisCipherText(name).toArray());
        param.put("cardNo", SensitiveInfoUtils.getAllHisCipherText(identityCode).toArray());
        param.put("mobile", SensitiveInfoUtils.getAllHisCipherText(mobile).toArray());
        param.put("bankCardNo", SensitiveInfoUtils.getAllHisCipherText(bankCardNo).toArray());
        /**end*/
        
        param.put("certifyCode", outStlmcd);
        
        List<BisRealNameCertify> resultList=null;
        try{
            resultList = this.findByHql(hql.toString(), param);
        }catch(Exception e){
            logger.info("查询四要素认证记录出现问题："+e.getMessage());
        }
        if (resultList == null || resultList.size() == 0) {
            return null;
        }
        return resultList.get(0);
    }

}
